<template>
  <div class="app-container">
    <el-form label-width="88px" :inline="true" class="demo-ruleForm">
      <el-form-item label="操作模块">
        <el-input placeholder="操作模块" clearable size="small" v-model="searchObj.title"></el-input>
      </el-form-item>
      <el-form-item label="操作人">
        <el-input placeholder="操作人" clearable size="small" v-model="searchObj.operName"></el-input>
      </el-form-item>
      <el-form-item label="操作时间">
        <el-date-picker
          size="small"
          v-model="createTimes"
          type="daterange"
          range-separator="至"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          value-format="yyyy-MM-dd"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="fetchData()">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetData">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table
      v-loading="listLoading"
      :data="list"
      stripe
      border
      style="width: 100%;margin-top: 10px;"
    >

      <el-table-column
        label="序号"
        width="70"
        align="center"
      >
        <template slot-scope="scope">
          {{ (page - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>

      <el-table-column prop="title" label="操作模块" align="center"/>
      <el-table-column prop="businessType" label="操作类型" align="center">
        <!--        <template slot-scope="scope">-->
        <!--          <el-input type="success" v-if='scope.row.businessType === "ASSGIN"'>其它</el-input>-->
        <!--          <el-input type="success" v-if='scope.row.businessType === "INSERT"'>新增</el-input>-->
        <!--          <el-input type="success" v-if='scope.row.businessType === "UPDATE"'>修改</el-input>-->
        <!--          <el-input type="success" v-if='scope.row.businessType === "DELETE"'>删除</el-input>-->
        <!--        </template>-->
      </el-table-column>

      <el-table-column prop="requestMethod" label="请求方式" align="center"/>

      <el-table-column prop="operName" label="操作人员" align="center"/>
      <el-table-column prop="operIp" label="操作IP" align="center"/>
      <el-table-column prop="method" label="请求方法" align="center"/>
      <el-table-column prop="status" label="操作状态" align="center"/>
      <el-table-column prop="createTime" label="创建时间" align="center"/>

      <el-table-column label="操作" align="center" fixed="right">
        <template slot-scope="scope">
          <el-button type="text" @click="details(scope.row.id)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="详情" :visible.sync="dialogVisible" width="40%">
      <el-form ref="dataForm" :model="sysOperLog" label-width="100px" size="small" style="padding-right: 40px;">
        <el-form-item label="操作模块" prop="title">
          <el-input v-model="sysOperLog.title" :readonly="true"/>
        </el-form-item>
        <el-form-item v-model="sysOperLog.businessType" label="操作类型" prop="businessType">
          <el-input v-model="sysOperLog.businessType" :readonly="true"/>
          <!--          <el-input v-if="sysOperLog.businessType === 'ASSGIN'" >其它</el-input>-->
          <!--          <el-input v-if="sysOperLog.businessType === 'INSERT'" >新增</el-input>-->
          <!--          <el-input v-if="sysOperLog.businessType === 'UPDATE'" >修改</el-input>-->
          <!--          <el-input v-if="sysOperLog.businessType === 'DELETE'" >删除</el-input>-->
        </el-form-item>
        <el-form-item label="请求方式" prop="requestMethod">
          <el-input v-model="sysOperLog.requestMethod" :readonly="true"/>
        </el-form-item>
        <el-form-item label="操作人员" prop="operName">
          <el-input v-model="sysOperLog.operName" :readonly="true"/>
        </el-form-item>
        <el-form-item label="请求路径" prop="operUrl">
          <el-input v-model="sysOperLog.operUrl" :readonly="true"/>
        </el-form-item>
        <el-form-item label="IP地址" prop="operIp">
          <el-input v-model="sysOperLog.operIp" :readonly="true"/>
        </el-form-item>
        <el-form-item label="请求参数" prop="operParam">
          <el-input v-model="sysOperLog.operParam" :readonly="true"/>
        </el-form-item>
        <el-form-item label="操作状态" prop="status">
          <el-input v-model="sysOperLog.status" :readonly="true"/>
        </el-form-item>
        <el-form-item label="创建时间" prop="createTime">
          <el-input v-model="sysOperLog.createTime" :readonly="true"/>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false" size="small">关 闭</el-button>
      </span>
    </el-dialog>

    <!-- 分页组件 -->
    <el-pagination
      :current-page="page"
      :total="total"
      :page-size="limit"
      style="padding: 30px 0; text-align: right;"
      layout="total, prev, pager, next, jumper"
      @current-change="fetchData"
    />

  </div>
</template>

<script>
import api from '@/api/system/log'

export default {
  // 定义数据
  data() {
    return {
      listLoading: false, // 数据是否正在加载
      list: null, // 列表
      total: 0, // 数据库中的总记录数
      page: 1, // 默认页码
      limit: 10, // 每页记录数
      searchObj: {}, // 查询表单对象

      sysOperLog: {},

      dialogVisible: false,

      createTimes: []
    }
  },

  created() {
    this.fetchData()
  },

  methods: {
    fetchData(page = 1) {
      this.page = page
      if (this.createTimes && this.createTimes.length === 2) {
        this.searchObj.createTimeBegin = this.createTimes[0]
        this.searchObj.createTimeEnd = this.createTimes[1]
      }

      api.getOperPageList(this.page, this.limit, this.searchObj)
        .then(response => {
          this.list = response.data.records
          this.total = response.data.total
        })
    },
    resetData() {
      this.searchObj = {}
      this.createTimes = []
      this.fetchData()
    },
    details(id) {
      this.dialogVisible = true
      api.getOperdetails(id).then(res => {
        this.sysOperLog = res.data
      })
    }

  }
}
</script>
